package com.shanghaionstar.wxapi;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.onstar.cn.common.util.PayMeConstants;
import com.onstar.cn.framework.mvp.base.core.BaseActivity;
import com.onstar.cn.framework.mvp.base.core.BasePresenter;
import com.shanghaionstar.R;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;


/**
 * 微信分享回调类
 *
 * @author 7828wc
 */
public class WXEntryActivity extends BaseActivity implements IWXAPIEventHandler {
    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        api = WXAPIFactory.createWXAPI(this, PayMeConstants.APP_ID, true);
        api.handleIntent(getIntent(), this);

    }

    @Override
    public BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void onReq(BaseReq arg0) {

    }

    @Override
    public void onResp(BaseResp resp) {
        String result = "";

        switch (resp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                result = getString(R.string.wx_send_success);
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                result = getString(R.string.wx_send_cancel);
                break;
            case BaseResp.ErrCode.ERR_UNSUPPORT:
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
            case BaseResp.ErrCode.ERR_SENT_FAILED:
                result = getString(R.string.wx_send_failed);
                break;
            default:
                result = getString(R.string.wx_send_failed);
                break;
        }
        Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
        // TODO 微信分享 成功之后调用接口
        this.finish();
    }

}
